import unittest
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from base.base_driver import driver_setup
from base.base_page import BasePage
from po.camera.camera_page import CameraPage
from po.common.common import Common
from po.home.home_page import HomePage
from HTMLTestReportCN import DirAndFiles

class Img2Word(unittest.TestCase, BasePage):
    @classmethod
    def setUpClass(cls):
        cls.driver = driver_setup()
        cls.home_page = HomePage(driver=cls.driver)
        cls.camera_page = CameraPage(driver=cls.driver)
        cls.common = Common(driver=cls.driver)

    def test_01_img2word(self):
        """拍图转Word-过滤-横屏查看-复制"""
        self.home_page.btn_img2word()
        self.camera_page.func_tip_close()
        self.camera_page.func_import_document()
        self.common.btn_filter()
        self.common.btn_all_select()
        sleep(1)
        DirAndFiles.get_screenshot(self.driver, "拍图转Word")
        sleep(1)
        self.common.btn_land()
        WebDriverWait(self.driver, 200).until(EC.presence_of_element_located((By.ID, self.HW_ENV + "picnum")))
        sleep(1)
        DirAndFiles.get_screenshot(self.driver, "拍图转Word_横屏查看")
        sleep(1)
        self.driver.keyevent(4)
        self.common.btn_copy()
        sleep(1)

    def test_02_export_word(self):
        """拍图转Word-导出word"""
        self.common.func_edit_filename("拍图转Word")
        self.common.btn_export()
        self.common.func_export()
        sleep(1)

    def test_03_export_pdf(self):
        """拍图转Word-导出pdf"""
        self.common.btn_img_page()
        self.common.btn_export()
        self.common.func_export()
        sleep(1)

    def test_04_export_img(self):
        """拍图转Word-导出图片"""
        self.common.btn_export()
        self.common.btn_img()
        self.common.func_export()
        sleep(1)
        # self.common.btn_export()
        # self.common.btn_long_img()
        # self.common.func_export_to_wechat()
        # sleep(1)
        self.driver.keyevent(4)

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()


if __name__ == "__main__":
    unittest.main()